package hu.fic.weddingstorefinder.db.generatedtable;

import android.app.Activity;
import android.content.ContentValues;
import android.database.sqlite.SQLiteDatabase;
import android.util.Log;

import hu.fic.weddingstorefinder.db.Table;

public class GeneratedPOI extends Table {
	private static final String LOG_TAG = "GeneratedPOI";

	public static final String TAB_NAME = "POI";

	//variables for POIId
	public static final String COL_POIID = "POIId";
	public static final int INT_COL_POIID = 0;
	protected Integer filter_POIID = null;

	//variables for CustomPOIId
	public static final String COL_CUSTOMPOIID = "CustomPOIId";
	public static final int INT_COL_CUSTOMPOIID = 1;
	protected Integer filter_CUSTOMPOIID = null;
	protected Integer set_CUSTOMPOIID = null;
	protected boolean forced_CUSTOMPOIID = false;

	//variables for Longitude
	public static final String COL_LONGITUDE = "Longitude";
	public static final int INT_COL_LONGITUDE = 2;
	protected Double filter_LONGITUDE = null;
	protected Double set_LONGITUDE = null;
	protected boolean forced_LONGITUDE = false;

	//variables for Latitude
	public static final String COL_LATITUDE = "Latitude";
	public static final int INT_COL_LATITUDE = 3;
	protected Double filter_LATITUDE = null;
	protected Double set_LATITUDE = null;
	protected boolean forced_LATITUDE = false;

	//variables for Address
	public static final String COL_ADDRESS = "Address";
	public static final int INT_COL_ADDRESS = 4;
	protected String filter_ADDRESS = null;
	protected String set_ADDRESS = null;
	protected boolean forced_ADDRESS = false;

	//variables for City
	public static final String COL_CITY = "City";
	public static final int INT_COL_CITY = 5;
	protected String filter_CITY = null;
	protected String set_CITY = null;
	protected boolean forced_CITY = false;

	//variables for Phone
	public static final String COL_PHONE = "Phone";
	public static final int INT_COL_PHONE = 6;
	protected String filter_PHONE = null;
	protected String set_PHONE = null;
	protected boolean forced_PHONE = false;

	//variables for POIName
	public static final String COL_POINAME = "POIName";
	public static final int INT_COL_POINAME = 7;
	protected String filter_POINAME = null;
	protected String set_POINAME = null;
	protected boolean forced_POINAME = false;

	//variables for ZIPCode
	public static final String COL_ZIPCODE = "ZIPCode";
	public static final int INT_COL_ZIPCODE = 8;
	protected String filter_ZIPCODE = null;
	protected String set_ZIPCODE = null;
	protected boolean forced_ZIPCODE = false;

	//variables for POIStatus
	public static final String COL_POISTATUS = "POIStatus";
	public static final int INT_COL_POISTATUS = 9;
	protected Integer filter_POISTATUS = null;
	protected Integer set_POISTATUS = null;
	protected boolean forced_POISTATUS = false;

	private boolean loaded = false;

	//constructor
	public GeneratedPOI(SQLiteDatabase db, Activity activity) {
		super(db, activity);
	}

	//methods for POIId
	public void setPOIId(int p) {
		this.filter_POIID = new Integer(p);
	}

	public int getPOIId() {
		if (this.loaded) {
			return this.cursor.getInt(INT_COL_POIID);
		} else {
			return this.filter_POIID.intValue();
		}
	}

	//methods for CustomPOIId
	public void setCustomPOIId(int p) {
		this.filter_CUSTOMPOIID = new Integer(p);
	}

	public int getCustomPOIId() {
		if (this.loaded) {
			return this.cursor.getInt(INT_COL_CUSTOMPOIID);
		} else {
			return this.filter_CUSTOMPOIID.intValue();
		}
	}
	public void addCustomPOIIdUpdate(int p) throws Exception {
		if (!this.loaded) {
			this.set_CUSTOMPOIID = new Integer(p);
		} else {
			throw new Exception("The addCustomPOIIdUpdate() cannot be used after load.");
		}
	}
	public void forceCustomPOIIdColumn() throws Exception {
		if (!this.loaded) {
			this.forced_CUSTOMPOIID = true;
		} else {
			throw new Exception("The forcedCustomPOIIdColumn() cannot be used after load.");
		}
	}

	//methods for Longitude
	public void setLongitude(double p) {
		this.filter_LONGITUDE = new Double(p);
	}

	public double getLongitude() {
		if (this.loaded) {
			return this.cursor.getDouble(INT_COL_LONGITUDE);
		} else {
			return this.filter_LONGITUDE.doubleValue();
		}
	}
	public void addLongitudeUpdate(double p) throws Exception {
		if (!this.loaded) {
			this.set_LONGITUDE = new Double(p);
		} else {
			throw new Exception("The addLongitudeUpdate() cannot be used after load.");
		}
	}
	public void forceLongitudeColumn() throws Exception {
		if (!this.loaded) {
			this.forced_LONGITUDE = true;
		} else {
			throw new Exception("The forcedLongitudeColumn() cannot be used after load.");
		}
	}

	//methods for Latitude
	public void setLatitude(double p) {
		this.filter_LATITUDE = new Double(p);
	}

	public double getLatitude() {
		if (this.loaded) {
			return this.cursor.getDouble(INT_COL_LATITUDE);
		} else {
			return this.filter_LATITUDE.doubleValue();
		}
	}
	public void addLatitudeUpdate(double p) throws Exception {
		if (!this.loaded) {
			this.set_LATITUDE = new Double(p);
		} else {
			throw new Exception("The addLatitudeUpdate() cannot be used after load.");
		}
	}
	public void forceLatitudeColumn() throws Exception {
		if (!this.loaded) {
			this.forced_LATITUDE = true;
		} else {
			throw new Exception("The forcedLatitudeColumn() cannot be used after load.");
		}
	}

	//methods for Address
	public void setAddress(String p) {
		this.filter_ADDRESS = p;
	}

	public String getAddress() {
		if (this.loaded) {
			return this.cursor.getString(INT_COL_ADDRESS);
		} else {
			return this.filter_ADDRESS;
		}
	}
	public void addAddressUpdate(String p) throws Exception {
		if (!this.loaded) {
			this.set_ADDRESS = p;
		} else {
			throw new Exception("The addAddressUpdate() cannot be used after load.");
		}
	}
	public void forceAddressColumn() throws Exception {
		if (!this.loaded) {
			this.forced_ADDRESS = true;
		} else {
			throw new Exception("The forcedAddressColumn() cannot be used after load.");
		}
	}

	//methods for City
	public void setCity(String p) {
		this.filter_CITY = p;
	}

	public String getCity() {
		if (this.loaded) {
			return this.cursor.getString(INT_COL_CITY);
		} else {
			return this.filter_CITY;
		}
	}
	public void addCityUpdate(String p) throws Exception {
		if (!this.loaded) {
			this.set_CITY = p;
		} else {
			throw new Exception("The addCityUpdate() cannot be used after load.");
		}
	}
	public void forceCityColumn() throws Exception {
		if (!this.loaded) {
			this.forced_CITY = true;
		} else {
			throw new Exception("The forcedCityColumn() cannot be used after load.");
		}
	}

	//methods for Phone
	public void setPhone(String p) {
		this.filter_PHONE = p;
	}

	public String getPhone() {
		if (this.loaded) {
			return this.cursor.getString(INT_COL_PHONE);
		} else {
			return this.filter_PHONE;
		}
	}
	public void addPhoneUpdate(String p) throws Exception {
		if (!this.loaded) {
			this.set_PHONE = p;
		} else {
			throw new Exception("The addPhoneUpdate() cannot be used after load.");
		}
	}
	public void forcePhoneColumn() throws Exception {
		if (!this.loaded) {
			this.forced_PHONE = true;
		} else {
			throw new Exception("The forcedPhoneColumn() cannot be used after load.");
		}
	}

	//methods for POIName
	public void setPOIName(String p) {
		this.filter_POINAME = p;
	}

	public String getPOIName() {
		if (this.loaded) {
			return this.cursor.getString(INT_COL_POINAME);
		} else {
			return this.filter_POINAME;
		}
	}
	public void addPOINameUpdate(String p) throws Exception {
		if (!this.loaded) {
			this.set_POINAME = p;
		} else {
			throw new Exception("The addPOINameUpdate() cannot be used after load.");
		}
	}
	public void forcePOINameColumn() throws Exception {
		if (!this.loaded) {
			this.forced_POINAME = true;
		} else {
			throw new Exception("The forcedPOINameColumn() cannot be used after load.");
		}
	}

	//methods for ZIPCode
	public void setZIPCode(String p) {
		this.filter_ZIPCODE = p;
	}

	public String getZIPCode() {
		if (this.loaded) {
			return this.cursor.getString(INT_COL_ZIPCODE);
		} else {
			return this.filter_ZIPCODE;
		}
	}
	public void addZIPCodeUpdate(String p) throws Exception {
		if (!this.loaded) {
			this.set_ZIPCODE = p;
		} else {
			throw new Exception("The addZIPCodeUpdate() cannot be used after load.");
		}
	}
	public void forceZIPCodeColumn() throws Exception {
		if (!this.loaded) {
			this.forced_ZIPCODE = true;
		} else {
			throw new Exception("The forcedZIPCodeColumn() cannot be used after load.");
		}
	}

	//methods for POIStatus
	public void setPOIStatus(int p) {
		this.filter_POISTATUS = new Integer(p);
	}

	public int getPOIStatus() {
		if (this.loaded) {
			return this.cursor.getInt(INT_COL_POISTATUS);
		} else {
			return this.filter_POISTATUS.intValue();
		}
	}
	public void addPOIStatusUpdate(int p) throws Exception {
		if (!this.loaded) {
			this.set_POISTATUS = new Integer(p);
		} else {
			throw new Exception("The addPOIStatusUpdate() cannot be used after load.");
		}
	}
	public void forcePOIStatusColumn() throws Exception {
		if (!this.loaded) {
			this.forced_POISTATUS = true;
		} else {
			throw new Exception("The forcedPOIStatusColumn() cannot be used after load.");
		}
	}

	public void loadAll() throws Exception {
		load();
	}

	public void load(String sql) throws Exception {
		this.loaded = true;
		super.load(sql);
	}

	public void load() throws Exception {
		SQLStatement sql = new SQLStatement();
		sql.addTable(TAB_NAME);

		sql.addIntFilter(COL_POIID, this.filter_POIID);
		if (!this.forced_CUSTOMPOIID || this.filter_CUSTOMPOIID != null) {
			sql.addIntFilter(COL_CUSTOMPOIID, this.filter_CUSTOMPOIID);
		} else {
			sql.addNullFilter(COL_CUSTOMPOIID);
		}
		if (!this.forced_LONGITUDE || this.filter_LONGITUDE != null) {
			sql.addDoubleFilter(COL_LONGITUDE, this.filter_LONGITUDE);
		} else {
			sql.addNullFilter(COL_LONGITUDE);
		}
		if (!this.forced_LATITUDE || this.filter_LATITUDE != null) {
			sql.addDoubleFilter(COL_LATITUDE, this.filter_LATITUDE);
		} else {
			sql.addNullFilter(COL_LATITUDE);
		}
		if (!this.forced_ADDRESS || this.filter_ADDRESS != null) {
			sql.addStrFilter(COL_ADDRESS, this.filter_ADDRESS);
		} else {
			sql.addNullFilter(COL_ADDRESS);
		}
		if (!this.forced_CITY || this.filter_CITY != null) {
			sql.addStrFilter(COL_CITY, this.filter_CITY);
		} else {
			sql.addNullFilter(COL_CITY);
		}
		if (!this.forced_PHONE || this.filter_PHONE != null) {
			sql.addStrFilter(COL_PHONE, this.filter_PHONE);
		} else {
			sql.addNullFilter(COL_PHONE);
		}
		if (!this.forced_POINAME || this.filter_POINAME != null) {
			sql.addStrFilter(COL_POINAME, this.filter_POINAME);
		} else {
			sql.addNullFilter(COL_POINAME);
		}
		if (!this.forced_ZIPCODE || this.filter_ZIPCODE != null) {
			sql.addStrFilter(COL_ZIPCODE, this.filter_ZIPCODE);
		} else {
			sql.addNullFilter(COL_ZIPCODE);
		}
		if (!this.forced_POISTATUS || this.filter_POISTATUS != null) {
			sql.addIntFilter(COL_POISTATUS, this.filter_POISTATUS);
		} else {
			sql.addNullFilter(COL_POISTATUS);
		}

		sql.addTail(" ORDER BY " + COL_POIID);
		load(sql.getSql());
	}

	public void clear() {
		this.filter_POIID = null;

		this.filter_CUSTOMPOIID = null;
		this.set_CUSTOMPOIID = null;
		this.forced_CUSTOMPOIID = false;

		this.filter_LONGITUDE = null;
		this.set_LONGITUDE = null;
		this.forced_LONGITUDE = false;

		this.filter_LATITUDE = null;
		this.set_LATITUDE = null;
		this.forced_LATITUDE = false;

		this.filter_ADDRESS = null;
		this.set_ADDRESS = null;
		this.forced_ADDRESS = false;

		this.filter_CITY = null;
		this.set_CITY = null;
		this.forced_CITY = false;

		this.filter_PHONE = null;
		this.set_PHONE = null;
		this.forced_PHONE = false;

		this.filter_POINAME = null;
		this.set_POINAME = null;
		this.forced_POINAME = false;

		this.filter_ZIPCODE = null;
		this.set_ZIPCODE = null;
		this.forced_ZIPCODE = false;

		this.filter_POISTATUS = null;
		this.set_POISTATUS = null;
		this.forced_POISTATUS = false;

		this.loaded = false;
		super.clear();
	}

	public long newRow() throws Exception {
		try {
			ContentValues newTaskValues = new ContentValues();
			newTaskValues.put(COL_CUSTOMPOIID, filter_CUSTOMPOIID);
			newTaskValues.put(COL_LONGITUDE, filter_LONGITUDE);
			newTaskValues.put(COL_LATITUDE, filter_LATITUDE);
			newTaskValues.put(COL_ADDRESS, filter_ADDRESS);
			newTaskValues.put(COL_CITY, filter_CITY);
			newTaskValues.put(COL_PHONE, filter_PHONE);
			newTaskValues.put(COL_POINAME, filter_POINAME);
			newTaskValues.put(COL_ZIPCODE, filter_ZIPCODE);
			newTaskValues.put(COL_POISTATUS, filter_POISTATUS);
			return this.db.insert(TAB_NAME, null, newTaskValues);
		} catch (Exception e) {
			Log.e(LOG_TAG, "Cannot execute inserting (" + e.getMessage() + ")", e);
			throw new Exception("Insert failed, see log file for details!");
		}
	}

	public void delete() throws Exception {
		SQLStatement sql = new SQLStatement();
		sql.addTable(TAB_NAME);
		sql.addIntFilter(COL_POIID, this.filter_POIID);
		sql.addIntFilter(COL_CUSTOMPOIID, this.filter_CUSTOMPOIID);
		sql.addDoubleFilter(COL_LONGITUDE, this.filter_LONGITUDE);
		sql.addDoubleFilter(COL_LATITUDE, this.filter_LATITUDE);
		sql.addStrFilter(COL_ADDRESS, this.filter_ADDRESS);
		sql.addStrFilter(COL_CITY, this.filter_CITY);
		sql.addStrFilter(COL_PHONE, this.filter_PHONE);
		sql.addStrFilter(COL_POINAME, this.filter_POINAME);
		sql.addStrFilter(COL_ZIPCODE, this.filter_ZIPCODE);
		sql.addIntFilter(COL_POISTATUS, this.filter_POISTATUS);
		this.db.execSQL(sql.getDeleteSql());
	}

	public void deleteAllRows() throws Exception {
		SQLStatement sql = new SQLStatement();
		sql.addTable(TAB_NAME);
		this.db.execSQL(sql.getDeleteAllSql());
	}

	public void update() throws Exception {
		SQLStatement sql = new SQLStatement();
		sql.addTable(TAB_NAME);

		sql.addIntFilter(COL_POIID, this.filter_POIID);

		sql.addIntFilter(COL_CUSTOMPOIID, this.filter_CUSTOMPOIID);
		sql.addIntSet(COL_CUSTOMPOIID, this.set_CUSTOMPOIID);

		sql.addDoubleFilter(COL_LONGITUDE, this.filter_LONGITUDE);
		sql.addDoubleSet(COL_LONGITUDE, this.set_LONGITUDE);

		sql.addDoubleFilter(COL_LATITUDE, this.filter_LATITUDE);
		sql.addDoubleSet(COL_LATITUDE, this.set_LATITUDE);

		sql.addStrFilter(COL_ADDRESS, this.filter_ADDRESS);
		sql.addStringSet(COL_ADDRESS, this.set_ADDRESS);

		sql.addStrFilter(COL_CITY, this.filter_CITY);
		sql.addStringSet(COL_CITY, this.set_CITY);

		sql.addStrFilter(COL_PHONE, this.filter_PHONE);
		sql.addStringSet(COL_PHONE, this.set_PHONE);

		sql.addStrFilter(COL_POINAME, this.filter_POINAME);
		sql.addStringSet(COL_POINAME, this.set_POINAME);

		sql.addStrFilter(COL_ZIPCODE, this.filter_ZIPCODE);
		sql.addStringSet(COL_ZIPCODE, this.set_ZIPCODE);

		sql.addIntFilter(COL_POISTATUS, this.filter_POISTATUS);
		sql.addIntSet(COL_POISTATUS, this.set_POISTATUS);

		this.db.execSQL(sql.getUpdateSql());
	}

}